package cn.yaboya.basic.controller;


import cn.yaboya.basic.exception.BusinessException;
import cn.yaboya.basic.service.IVerifyCodeService;
import cn.yaboya.basic.utils.AjaxResult;
import cn.yaboya.basic.vo.RegisterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* @Title:
* @Description: 登录公共类窗口
* @Author: LT
* @Version: 1.0
* @Date:  2022/7/5 10:12
* @Parameters:
* @Return
*/
@RequestMapping("/verifyCode")
@RestController
public class VerifyCodeController {

    @Autowired
    IVerifyCodeService verifyCodeService;

    /**
    * @Title: graph
    * @Description: 图像验证码接受窗口
    * @Author: LT
    * @Version: 1.0
    * @Date:  2022/7/5 10:12
    * @Parameters: [key]
    * @Return cn.yaboya.basic.utils.AjaxResult
    */
    @GetMapping("/image/{key}")
    public AjaxResult graph (@PathVariable String key){
        try {
            String base64Str = verifyCodeService.graph(key);
            return new AjaxResult().me().setResultObj(base64Str);
        } catch (BusinessException e) {
            e.printStackTrace();
            return new AjaxResult().me().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new  AjaxResult().me().setSuccess(false).setMessage("系统繁忙，请重试！");
        }
    }


    @PostMapping("/smsCode")
    public AjaxResult smsCode (@RequestBody RegisterVo vo){
        try {
            verifyCodeService.smsCode(vo);
            return new AjaxResult().me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return new AjaxResult().me().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new  AjaxResult().me().setSuccess(false).setMessage("系统繁忙，请重试！");
        }
    }
}
